//
//  PywPayPwdHeaderView.m
//  PywSdk
//
//  Created by smallwave on 16/8/17.
//  Copyright © 2016年 zero. All rights reserved.
//

#import "PywPayPwdHeaderView.h"
#import "UILabel+Pyw.h"
#import "PywPasswordView.h"
#import "PywMasonry.h"

@interface PywPayPwdHeaderView ()

@property (nonatomic, strong) UILabel           *propmtLabel;   // 提示输入信息
@property (nonatomic, strong) PywPasswordView   *pwdInputView;  // 密码输入框
@property (nonatomic, strong) UILabel           *problemLabel;  // 设置安全问题提示

@end

@implementation PywPayPwdHeaderView

#pragma mark - override
- (instancetype)init{
    self = [super init];
    if (self) {
        [self setUp];
    }
    return self;
}
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUp];
    }
    return self;
}
#pragma mark - prepareUI
- (void)setUp{
    self.backgroundColor = [UIColor clearColor];
    [self addSubviewAndLayoutSubviews];
}
- (void)addSubviewAndLayoutSubviews{
    [self addSubview:self.propmtLabel];
    [self addSubview:self.pwdInputView];
    [self addSubview:self.problemLabel];
    
    self.pwdInputView.elementCount = 6;
    self.pwdInputView.elementMargin = 0;
    self.pwdInputView.elementColor = [UIColor grayColor];
    self.pwdInputView.passwordBlock = ^(NSString *password){
        PLog(@"%@",password);
        self.payPwd = password;
    };
    
    __weak typeof(self) wSelf = self;
    [self.propmtLabel mas_makeConstraints:^(PywMASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.equalTo(wSelf.mas_top).offset(40);
        make.width.equalTo(wSelf.mas_width).multipliedBy(0.9);
    }];
    [self.pwdInputView mas_makeConstraints:^(PywMASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.equalTo(wSelf.propmtLabel.mas_bottom).offset(20);
        make.width.equalTo(wSelf.propmtLabel.mas_width);
        make.height.equalTo(@40);
    }];
    [self.problemLabel mas_makeConstraints:^(PywMASConstraintMaker *make) {
        make.centerX.offset(0);
        make.top.equalTo(wSelf.pwdInputView.mas_bottom).offset(40);
        make.width.equalTo(wSelf.pwdInputView.mas_width);
        make.bottom.equalTo(wSelf.mas_bottom).offset(-20);
    }];
}
#pragma mark - Lazy
- (UILabel *)propmtLabel{
    if (!_propmtLabel) {
        _propmtLabel = [UILabel labelWithText:@"请设置6位数字交易密码"
                                textAlignment:NSTextAlignmentLeft
                                     fontSize:14
                                    textColor:[UIColor blackColor]];
    }
    return _propmtLabel;
}
- (PywPasswordView *)pwdInputView{
    if (!_pwdInputView) {
        _pwdInputView = [[PywPasswordView alloc] init];
        _pwdInputView.backgroundColor = [UIColor whiteColor];
        _pwdInputView.layer.cornerRadius = 10;
        _pwdInputView.layer.masksToBounds = YES;
        _pwdInputView.layer.borderWidth = 1;
        _pwdInputView.layer.borderColor = [UIColor grayColor].CGColor;
    }
    return _pwdInputView;
}
- (UILabel *)problemLabel{
    if (!_problemLabel) {
        _problemLabel = [UILabel labelWithText:@"请设置交易密码找回安全问题"
                                 textAlignment:NSTextAlignmentLeft
                                      fontSize:14
                                     textColor:[UIColor blackColor]];
    }
    return _problemLabel;
}

@end
